package demo2;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author 24岁没牵过女人的手 日期：2023/7/5 17:00 文件描述：
 */
public class SwingObserverExample {
  JFrame jFrame;

  public static void main(String[] args) {
    SwingObserverExample swingObserverExample = new SwingObserverExample();
    swingObserverExample.go();
  }

  public void go() {
    jFrame = new JFrame();
    JButton jButton = new JButton("should i do it ?");
    jButton.addActionListener(new AngelListener());
    jButton.addActionListener(new DevilListener());
    jFrame.getContentPane().add(BorderLayout.CENTER, jButton);
  }

  class AngelListener implements ActionListener {
    public void actionPerformed(ActionEvent action) {
      System.out.println("Don't do it, you might regret it !");
    }
  }

  class DevilListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      System.out.println("Come on, do it");
    }
  }
}
